package com.jml.队列和线程池;


import com.jml.Lock.ReentrantLockTest;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @author:jml
 * @date: 2019/5/5 13:37
 * @description：
 */
public class ArrayBlockingQueue和ReetrantLock {
    public static BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<String>(3);

    public static class T1 extends Thread{
        @Override
        public void run() {
            for (int i = 0; i <10000 ; i++) {
                try {
                    blockingQueue.put("a"+i);
                    System.out.println("放入元素："+"a"+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
    public static class T2 extends Thread{
        @Override
        public void run() {
            for (int i = 0; i <10000 ; i++) {
                try {
                    blockingQueue.put("b"+i);
                    System.out.println("放入元素："+"b"+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static class T3 extends Thread{
        @Override
        public void run() {
            for (int i = 0; i <10000 ; i++) {
                try {
                    blockingQueue.put("c"+i);
                    System.out.println("放入元素："+"c"+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new T1().start();
        Thread.sleep(1000);
        new T2().start();
        Thread.sleep(1000);
        new T3().start();
        Thread.sleep(1000);
        for (int i = 0; i <10000 ; i++) {
            Thread.sleep(3000);
            blockingQueue.take();
//            System.out.println("取出元素："+blockingQueue.take());
        }

    }
}
